<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>

<html>
	<head>
		<title>自处理任务管理</title>
		<%@ include file="/common/meta.jsp"%>
		<%@ include file="/common/jquery-ui-inc.jsp"%>
		<script>
//$.messager.defaults={ok:"确定",cancel:"取消"};   

$(function() {
	$('#autoList').datagrid( {
		title : '自处理任务列表',
		url : '${ctx}/flow/core/flow-automatic!data.action',
		loadMsg : '数据载入中，请稍后……',
		nowrap : false,
		collapsible : false,
		fitColumns : true,
		pagination : true,
		singleSelect : true,
		rownumbers : true,
		remoteSort : false,
		pageList : [ 15, 50, 100 ],
		idField : 'dbId',
		columns : [ [{
			field : 'taskId',
			title : '任务id',
			width : 80,
			sorter : function(a, b) {
				return (a > b ? 1 : -1);
			}
		}, {
			title : '处理状态',
			field : 'handleStauts',
			width : 80,
			formatter: function(val, rec,rowIndex){
			    if(val=="0")return "<span style='color:red;'>未执行</span>";
				if(val=="1")return "<span style='color:red;'>执行失败</span>";
				if(val=="3")return "<span style='color:red;'>资源action为空</span>";
				else{
					return "<span style='color:green;'>标识为空或错误</span>";
				}
			}
		},{
			title : '流程实例Id',
			field : 'processInsId',
			width : 130
		},{
			title : '创建时间',
			field : 'createTime',
			width : 130
		},{
			title : '处理路径',
			field : 'handleUrl',
			width : 380
		}
		,{
			title : '执行时间',
			field : 'executeTime',
			width : 100,
			formatter:function(value,row,index){
				 if(value==null ||value=="" ){
				      return "<span style='color:red;'>即时</span>";
				  }else{
				      return value;
				  }
			}
		},{
			field : 'cz',
			title : '操作',
			width : 120,
			formatter:function(value,row,index){
				return '<a href="javascript:viewProcessPic(\''+row.processInsId+'\')" >查看流程图</a> &nbsp;&nbsp;<a href="javascript:executeTask(\''+row.handleUrl+'\')" >执行任务</a>';
			}
		}
		] ]
	});
});

	//执行自处理任务
     function executeTask(taskUrl){
       window.open(taskUrl);
     }
     
	//执行自处理任务(使用后台程序执行，还是使用定时器执行？)
	function executeAutoTask(id) {
			$.messager.confirm('确认', '您确定要删除:<font color="red">' + id + '</font> ？',
					function(r) {
						if (r) {
							$.ajax( {
								type : "post",
								url : "${ctx}/flow/core/flow-instance!del.action?processInstanceId="+ id,
								dataType:'json',
								beforeSend : function(XMLHttpRequest) {
									//ShowLoading();
								},
								success : function(data, textStatus) {
									var f = data.flag;
									if(f == "T"){
										$.messager.alert('结果', data.msg, 'info',function(){
											reload();
										});
									}else{
										$.messager.alert('错误', data.msg, 'error');
									}
									
								},
								complete : function(XMLHttpRequest, textStatus) {
									//HideLoading();
								},
								error : function() {
									//请求出错处理
								}
							});
						}
			});
	}
	//查看流程图
	function viewProcessPic(id){
		var url = "${ctx}/flow/core/flow-view-pic.action?processInsId="+id;
		$("#autoAddFrame").attr("src",url);
		$('#autoAddWin').window('open');
	}

	function reload(){
		$('#autoList').datagrid("reload");
	}
	
	function closeAddWin(){
		$('#autoAddWin').window('close');
	}


		
	function searchList(){					
	 	var queryParams = $('#autoList').datagrid('options').queryParams;	    
	       	var opt = $('#autoList').datagrid('options'); 
	       	$('#autoList').datagrid('options').pageNumber=1;
	        queryParams["handleStauts"] = $('#handleStauts').val();
	        queryParams["taskId"] = $('#taskId').val();
	        queryParams["processInsId"] = $('#processInsId').val();
	        $('#autoList').datagrid('reload');
	         var page = $('#autoList').datagrid('getPager');
	         page.pagination({pageNumber:1,pageSize:opt.pageSize});
	  }
	function clearSearch(){					
	   $('#handleStauts').val('');
       $('#taskId').val('');
       $('#processInsId').val('');
		   searchList(); 
	  }  
	  
			
	</script>
	</head>

	<body>
	
	 <div title="查询" id="list"  class="easyui-panel" icon="icon-search"  collapsible="true">
	 <form action="" id="eform" name="efrom" method="post">
        <table class="info"  cellpadding="0" cellspacing="1" id="seaExhibit">
                <tr>                   
                 <!--   <td class="datagrid-header">执行状态：</td>
                    <td>
                    <select name="handleStauts" id="handleStauts" style="width: 200px">
                    <option value="" selected="selected">请选择</option>
                    <option value="0">未执行</option>
                    <option value="1">执行失败</option>
                    </select>								
                    </td>  -->
                     <td class="datagrid-header">taskId：</td>
             		 <td> <input type=text id="taskId" name="taskId" value="" size=20 />&nbsp;&nbsp; </td>
             		   <td class="datagrid-header">流程实例id：</td>
                 <td> <input type=text id="processInsId" name="processInsId" value="" size=20 /> </td>    <td>&nbsp;<a class="easyui-linkbutton" iconCls="icon-search" onClick="searchList()">查 询</a>&nbsp;<a class="easyui-linkbutton" iconCls="icon-cut" onClick="clearSearch();">清空</a></td>          
                 </tr>  
            </table>
        </form>
        </div>
	
		<table id="autoList"></table>

		<div id="autoAddWin" class="easyui-window" title="查看流程图"
			style="padding: 5px; width: 1000px; height: 500;" 
			iconCls="icon-search" closed="true" maximizable="false"
			minimizable="false" collapsible="false" >
			<iframe frameborder="0" id="autoAddFrame" height="100%" width="100%"
				scrolling="yes" frameborder="0" style="position:relative;"></iframe>
		</div>

	</body>
</html>